package nio;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

/**
 * Created by Administrator on 2017/6/7.
 */
public class JDatagramChannelDemo2 {
    public static void main(String[] args) throws Exception{
        DatagramChannel dc = DatagramChannel.open();
        dc.socket().bind(new InetSocketAddress(9999));
        ByteBuffer buf = ByteBuffer.allocate(10);
        dc.receive(buf);

        String str = new String(buf.array(),0, buf.position());
        System.out.println(str);
    }
}
